<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
   function deepCopy(obj) {
  if (typeof obj !== 'object' || obj === null) {
    return obj;
  }

  let copy = Array.isArray(obj) ? [] : {};

  for (let key in obj) {
    if (obj.hasOwnProperty(key)) { // 只拷贝对象自身的属性，不包括从原型链继承来的属性
      copy[key] = deepCopy(obj[key]); // 递归拷贝子属性
    }
  }

  return copy;
}

const obj = {
  name:'jack',
  info:{
    age:18,
    six:'nan'
  }
}
const obj2 = deepCopy(obj)
obj2.info.age = 20
console.log(obj,obj2);
  </script>
</body>
</html>